
package com.ibeeking.found.report.rest.controller.v1;

import com.ibeeking.found.report.rest.service.IReportDashboardService;
import com.ibeeking.found.report.rest.service.IReportShareService;
import com.ibeeking.found.report.service.common.param.ReportShareParam;
import com.ibeeking.found.report.service.common.po.ResponseBean;
import com.ibeeking.found.report.service.common.vo.ChartVO;
import com.ibeeking.found.report.service.common.vo.ReportDashboardObjectVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* @desc 大屏设计 controller
* @website https://gitee.com/anji-plus/gaea
* @author Raod
* @date 2021-04-12 14:52:21.761
**/
@RestController
@RequestMapping("/reportDashboard/v1")
public class DmpReportDashboardController {

    @Resource
    private IReportDashboardService reportDashboardServiceImpl;

    @Resource
    private IReportShareService reportShareServiceImpl;

    /**
     * 预览、查询大屏详情
     * @param reportCode
     * @return
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "预览、查询大屏详情")
    @GetMapping({"/detail/{reportCode}"})
    public ResponseBean detail(@PathVariable("reportCode") String reportCode) {
        ReportDashboardObjectVO entityVO = reportDashboardServiceImpl.getDetail(reportCode);
        return ResponseBean.builder().data(entityVO).build();
    }

    /**
     * 保存大屏设计
     * @param dto
     * @return
     */
    @Log(logType = OperateLogTypeEnum.SAVE, describe = "保存大屏设计")
    @PostMapping("/insertDashboard")
    public ResponseBean insert(@RequestBody ReportDashboardObjectVO dto) {
        reportDashboardServiceImpl.insertDashboard(dto);
        return ResponseBean.builder().build();
    }


    /**
     * 获取去单个图层数据
     * @param dto
     * @return
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "获取去单个图层数据")
    @PostMapping("/getData")
    public ResponseBean getData(@RequestBody ChartVO dto) {
        Object objData = reportDashboardServiceImpl.getChartData(dto);
        return ResponseBean.builder().data(objData).build();
    }


    /**
     * 导出大屏
     * @param reportCode
     * @return
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "导出大屏")
    @GetMapping("/export")
    public ResponseEntity<byte[]> exportDashboard(HttpServletRequest request, HttpServletResponse response,
                                                  @RequestParam("reportCode") String reportCode, @RequestParam(value = "showDataSet",required = false, defaultValue = "1") Integer showDataSet) {
        return reportDashboardServiceImpl.exportDashboard(request, response, reportCode, showDataSet);
    }

    /**
     * 导入大屏
     * @param file  导入的zip文件
     * @param reportCode
     * @return
     */
    @Log(logType = OperateLogTypeEnum.SAVE, describe = "导入大屏")
    @PostMapping("/import/{reportCode}")
    public ResponseBean importDashboard(@RequestParam("file") MultipartFile file, @PathVariable("reportCode") String reportCode) {
        reportDashboardServiceImpl.importDashboard(file, reportCode);
        return ResponseBean.builder().build();
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "分享大屏")
    @PostMapping("/share")
    public ResponseBean share(@Validated @RequestBody ReportShareParam dto) {
        return ResponseBean.builder().data(reportShareServiceImpl.insertShare(dto)).build();
    }

}
